<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>北冥有鱼，其名为鲲</title>
        <meta name="description" content="" />
        <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
        <script src="//cdn.bootcss.com/jquery/1.11.1/jquery.js"></script>
        <link href="//cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css" rel="stylesheet" />
        <link href="//cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css" rel="stylesheet" />
        <script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
        <script src="//cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js"></script>
        <script src="//cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="//cdn.bootcss.com/sweetalert/2.1.2/sweetalert.min.js"></script>
        <script src="/static/js/md5.min.js"></script>
    </head>
    <body>

        {% include navbar.html %}

        <div class="panel panel-default"> 
            {% include panel_header.html %}
            <div class="panel-body">
                <table id="pluginListTable" class="table table-striped table-bordered" > 
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>author</th>
                                <th>remarks</th>
                                <th>type</th>
                                <th>target</th>
                                <th style="width:50px;">-</th>
                            </tr>
                        </thead>
                </table>
            </div>
        </div>
        <script type="text/javascript">
            $(function(){
                $("#pluginListTable").DataTable({
                    "pageLength":10,
                    "ajax":{
                        "url":"/api/pluginList",
                        "dataSrc":""
                    },
                    "columns":[
                        {"data":"name"},
                        {"data":"author"},
                        {"data":"remarks"},
                        {"data":"type"},
                        {"data":"target"},
                        {
                            "data":"name",
                            "render":function(data, type, full, meta){
                                var content = "-";
                                var user_define = data.substr(0,6);
                                if(user_define == "[user:") {
                                    var md5_hash = md5(data);
                                    content = "<a href='/page/plugin/edit?" + md5_hash + "'>" + 
                                        '<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>'
                                        +"</a> &nbsp;";

                                    content += "<a onclick='removePluginItem(this)' href='javascript:;' umd5='" + md5_hash + "'>" + 
                                        '<span class="glyphicon glyphicon-remove " aria-hidden="true"></span>'
                                        +"</a>";
                                }
                                return "<td>" + content +"</td>";
                            }
                        }
                    ]
                });
            });

            function removePluginItem(i){
                var md5 = $(i).attr("umd5");
                swal({
                     title:"确认删除!",
                     text:"确认删除这个插件么？删除插件以后，仍然需要重启poc-scanner才会生效!",
                     buttons: [true, "删除吧!"],
                     dangerMode:true,
                     icon: "warning"
                }).then(function(value){
                    if(value){
                        $.post("/api/plugin/remove",{md5:md5},function(data){
                            swal("删除成功!需要重启poc-scanner 才会生效!").then(function(){
                                location.href = location.href; 
                            });
                        });
                    }
                });
            }
        </script>
    </body>
</html>
